import Mock from 'mockjs';

const {mock} = Mock;

// 根据字典类型获取字典数据
mock(/\/api\/dict\/data\/\w+/, "get", (options) => {
    const typeCode = options.url.split('/').pop();
    const dataMap = {
        gender: [
            {id: "1", label: "男", value: "1", sort: 1, status: "1", remark: "男性"},
            {id: "2", label: "女", value: "2", sort: 2, status: "1", remark: "女性"},
            {id: "3", label: "未知", value: "3", sort: 3, status: "1", remark: "未知性别"}
        ],
        status: [
            {id: "4", label: "启用", value: "1", sort: 1, status: "1", remark: "启用状态"},
            {id: "5", label: "禁用", value: "0", sort: 2, status: "1", remark: "禁用状态"}
        ],
        yes_no: [
            {id: "6", label: "是", value: "1", sort: 1, status: "1", remark: "是"},
            {id: "7", label: "否", value: "0", sort: 2, status: "1", remark: "否"}
        ],
        user_type: [
            {id: "8", label: "管理员", value: "admin", sort: 1, status: "1", remark: "系统管理员"},
            {id: "9", label: "普通用户", value: "user", sort: 2, status: "1", remark: "普通用户"},
            {id: "10", label: "游客", value: "guest", sort: 3, status: "1", remark: "游客"}
        ],
        priority: [
            {id: "11", label: "高", value: "high", sort: 1, status: "1", remark: "高优先级"},
            {id: "12", label: "中", value: "medium", sort: 2, status: "1", remark: "中优先级"},
            {id: "13", label: "低", value: "low", sort: 3, status: "1", remark: "低优先级"}
        ]
    };
    console.log('typeCode', dataMap[typeCode]);
    return {
        code: 200,
        data: {
            total: dataMap[typeCode].total,
            list: dataMap[typeCode] || [],
        }
    };
});

// 获取所有字典数据（分页）
mock("/api/dict/data", "get", {
    code: 200,
    data: {
        total: 13,
        list: [
            {id: "1", typeCode: "gender", label: "男", value: "1", sort: 1, status: "1", remark: "男性"},
            {id: "2", typeCode: "gender", label: "女", value: "2", sort: 2, status: "1", remark: "女性"},
            {id: "3", typeCode: "gender", label: "未知", value: "3", sort: 3, status: "1", remark: "未知性别"},
            {id: "4", typeCode: "status", label: "启用", value: "1", sort: 1, status: "1", remark: "启用状态"},
            {id: "5", typeCode: "status", label: "禁用", value: "0", sort: 2, status: "1", remark: "禁用状态"},
            {id: "6", typeCode: "yes_no", label: "是", value: "1", sort: 1, status: "1", remark: "是"},
            {id: "7", typeCode: "yes_no", label: "否", value: "0", sort: 2, status: "1", remark: "否"},
            {
                id: "8",
                typeCode: "user_type",
                label: "管理员",
                value: "admin",
                sort: 1,
                status: "1",
                remark: "系统管理员"
            },
            {
                id: "9",
                typeCode: "user_type",
                label: "普通用户",
                value: "user",
                sort: 2,
                status: "1",
                remark: "普通用户"
            },
            {id: "10", typeCode: "user_type", label: "游客", value: "guest", sort: 3, status: "1", remark: "游客"},
            {id: "11", typeCode: "priority", label: "高", value: "high", sort: 1, status: "1", remark: "高优先级"},
            {id: "12", typeCode: "priority", label: "中", value: "medium", sort: 2, status: "1", remark: "中优先级"},
            {id: "13", typeCode: "priority", label: "低", value: "low", sort: 3, status: "1", remark: "低优先级"}
        ]
    }
});

// 添加字典数据
mock("/api/dict/data", "post", {
    code: 200,
    data: {
        id: Mock.Random.id(),
        message: "添加成功"
    }
});

// 更新字典数据
mock("/api/dict/data", "put", {
    code: 200,
    data: {
        message: "更新成功"
    }
});

// 删除字典数据
mock("/api/dict/data", "delete", {
    code: 200,
    data: {
        message: "删除成功"
    }
});